package com.patui.Ui;
import java.util.Map;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;

import com.patui.Database.Configure;
import com.patui.Database.WeiboConfig;
import com.patui.Logic.FrameSevice;
import com.patui.Utils.TextUtil;

public class LoginActivity extends Activity implements BaseActivity{
	private BindingReceiver mReceiver;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		FrameSevice.addActivity(LoginActivity.this);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		LoginLayout mLayout=new LoginLayout(this);
		this.setContentView(mLayout);
		mReceiver = new BindingReceiver();
		IntentFilter filter = new IntentFilter();
		filter.addAction("com.patui.Ui.LoginActivity");
		registerReceiver(mReceiver, filter);
		WeiboConfig.saveAccoutConfig(this);
		try {
			Configure.readConfig(this);
			System.out.println("key:"+Configure.getQQToken()+"\nsecret:"+Configure.getQQTokenSecret()+"\nuserId:"+Configure.getQQUserName());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
   public class BindingReceiver extends BroadcastReceiver
   {

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
//		    String url = intent.getStringExtra("urlStr");
//	        Uri uri = Uri.parse(url);
//	    	//获取sina accessToken和oauth_token_secret
//			String oauth_verifier = uri.getQueryParameter("oauth_verifier");
//			OAuth oAuth = OAuth.getInstance();
//			oAuth.setVerifier(oauth_verifier);
//			String accessToken = oAuth.getAccessToken();
//			System.out.println("accessToken:"+accessToken);
//			Map<String,String> map=TextUtil.splitResponse(accessToken);
//			System.out.println("key:"+map.get("oauth_token")+"\nsecret:"+map.get("oauth_token_secret")+"\nuserId:"+map.get("userId"));
//			Configure.setQQToken(map.get("oauth_token"));
//			Configure.setQQTokenSecret(map.get("oauth_token_secret"));
//			Configure.setQQUserName(map.get("userId"));
//			Configure.saveConfig(context);
//			if(null!=Configure.getQQToken()&&Configure.getQQToken().trim().length()>0)
//			{
//				Intent mIntentToMainTab=new Intent();
//				mIntentToMainTab.setClass(LoginActivity.this, MainTabActivity.class);
//				LoginActivity.this.startActivity(mIntentToMainTab);
//				
//			}
	}
	   
   }
@Override
public void init() {
	// TODO Auto-generated method stub
	
}
@Override
public void refresh() {
	// TODO Auto-generated method stub
	
}

}
